import * as actions from '../actions/view'
import { COMMANDS } from '../../commands'

export default function (keybindings, language) {
  const viewMenu = {
    label: language.getString('view'),
    submenu: [{
      label: language.getString('commandPalette'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_COMMAND_PALETTE),
      click (menuItem, focusedWindow) {
        actions.showCommandPalette(focusedWindow)
      }
    }, {
      type: 'separator'
    }, {
      id: 'sourceCodeModeMenuItem',
      label: language.getString('sourceCodeMode'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_SOURCE_CODE_MODE),
      type: 'checkbox',
      checked: false,
      click (item, focusedWindow) {
        actions.toggleSourceCodeMode(focusedWindow)
      }
    }, {
      id: 'typewriterModeMenuItem',
      label: language.getString('typewriterMode'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_TYPEWRITER_MODE),
      type: 'checkbox',
      checked: false,
      click (item, focusedWindow) {
        actions.toggleTypewriterMode(focusedWindow)
      }
    }, {
      id: 'focusModeMenuItem',
      label: language.getString('focusMode'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_FOCUS_MODE),
      type: 'checkbox',
      checked: false,
      click (item, focusedWindow) {
        actions.toggleFocusMode(focusedWindow)
      }
    }, {
      type: 'separator'
    }, {
      label: language.getString('showSidebar'),
      id: 'sideBarMenuItem',
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_TOGGLE_SIDEBAR),
      type: 'checkbox',
      checked: false,
      click (item, focusedWindow) {
        actions.toggleSidebar(focusedWindow)
      }
    }, {
      label: language.getString('showTabBar'),
      id: 'tabBarMenuItem',
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_TOGGLE_TABBAR),
      type: 'checkbox',
      checked: false,
      click (item, focusedWindow) {
        actions.toggleTabBar(focusedWindow)
      }
    }, {
      label: language.getString('toggleTableOfContents'),
      id: 'tocMenuItem',
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_TOGGLE_TOC),
      click (_, focusedWindow) {
        actions.showTableOfContents(focusedWindow)
      }
    }, {
      label: language.getString('reloadImages'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_FORCE_RELOAD_IMAGES),
      click (item, focusedWindow) {
        actions.reloadImageCache(focusedWindow)
      }
    }]
  }

  if (global.MARKTEXT_DEBUG) {
    viewMenu.submenu.push({
      type: 'separator'
    })
    viewMenu.submenu.push({
      label: language.getString('showDevTools'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_TOGGLE_DEV_TOOLS),
      click (item, win) {
        actions.debugToggleDevTools(win)
      }
    })
    viewMenu.submenu.push({
      label: language.getString('reloadWindow'),
      accelerator: keybindings.getAccelerator(COMMANDS.VIEW_DEV_RELOAD),
      click (item, focusedWindow) {
        actions.debugReloadWindow(focusedWindow)
      }
    })
  }

  return viewMenu
}
